package com.tong.hao.ac.service.controller.common.mybatis;

import com.tong.hao.common.configuration.mybatis.MybatisMapperRefresh;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName MybatisMapperController
 * @Author 友野浩二
 * @Date 2019/12/8 21:08
 * @Description mybatis mapper.xml 刷新
 * @Version 1.0
 */
@Api(tags = "MybatisPlusMapper.xml刷新-Mapper文件热加载")
@RestController
@Slf4j
public class MybatisMapperController {

    @Autowired
    private SqlSessionFactory sqlSessionFactory;

    @Value(value = "${mybatis-plus.mapper-locations}")
    private String mapperLocations;

    @ApiOperation(value = "mapper refresh")
    @RequestMapping(value = "/mapper/refresh", method = RequestMethod.GET)
    public String refreshMyBatisXml() {
        return new MybatisMapperRefresh(sqlSessionFactory, mapperLocations).readMapperXml();
    }

}
